package com.tingyuge.base.jdk.jdk8;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.google.common.primitives.Ints.asList;
import static java.util.stream.Collectors.toList;

/**
 * @Author zhangqp
 * @Description
 */
public class FlatMapTest {

    /**
     * more stream
     */
    @Test
    public void test1(){
        List<Integer> together = Stream.of(asList(1, 2), asList(3, 4))
                .flatMap(numbers -> numbers.stream())
                .collect(toList());
        System.out.println(together);
    }

    @Test
    public void test2(){
        List<String> stringList = Arrays.asList("hello", "world");
        Set<String[]> collect = stringList.stream().map(it -> it.split("")).collect(Collectors.toSet());
        collect.forEach(it-> System.out.println(Arrays.toString(it)));
        Set<String> result = stringList.stream().map(it -> it.split("")).flatMap(Arrays::stream)
                .distinct().collect(Collectors.toSet());
        System.out.println(result);
    }
}
